﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using DATA_operate_;
using System.Text;

public partial class design_page_admin_Default : System.Web.UI.Page
{
    DATA_operate publishinfo = new DATA_operate();

    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button2_Click(object sender, EventArgs e)   //发布
    {
        if(TextBox4.Text=="")
        {
            Page.ClientScript.RegisterStartupScript(this.GetType(), "right", "window.alert('公告消息不能为空');", true);
        }
        else
        {
            string _public_notice_id = Make_id();
            string _notice_content = TextBox4.Text;
            string _notice_send_time = DateTime.Now.ToLocalTime().ToString();
           // if (publishinfo.Data_update("_public_notice", "_Is_use","停止使用", "_Is_use","使用中"))
            publishinfo.Data_update("_public_notice", "_Is_use", "停止使用", "_Is_use", "使用中");
            if (publishinfo.dataadd("_public_notice", "_public_notice_id,_notice_content,_notice_send_time", _public_notice_id + "," + _notice_content + "," + _notice_send_time ))
            {
                
                Page.ClientScript.RegisterStartupScript(this.GetType(), "right", "window.alert('发布成功');", true);

            }
            else
                Page.ClientScript.RegisterStartupScript(this.GetType(), "right", "window.alert('发布失败。请稍后再次发送');", true);
          
        }
        
    }
    protected void Button3_Click(object sender, EventArgs e)   //重置
    {
        TextBox4.Text = "";
    }



    private string Make_id()   //生成作业ID
    {

        string numA = publishinfo.dataread("MAX(_public_notice_id)", "_public_notice", true);   //获得最大公告ID号
        if(numA==null)
        {
            numA = "0000000000000";
        }
        string numB = "1";   //最大ID 号加1
        numA = numA.Replace(" ", "");
        int lenA = 0, lenB = 0;
        int lenI = 0, intTen = 0;
        int intA = 0, intB = 0;

        StringBuilder result = new StringBuilder("");
        lenA = numA.Length;
        lenB = numB.Length;
        if (lenA > lenB)
            lenI = lenA;
        else
            lenI = lenB;
        for (int i = 0; i < lenI; i++)
        {
            if (i < lenA)
                intA = Convert.ToInt16(numA.Substring(lenA - i - 1, 1));
            else
                intA = 0;
            if (i < lenB)
                intB = Convert.ToInt16(numB.Substring(lenB - i - 1, 1));
            else
                intB = 0;
            int temp = intA + intB + intTen;
            result.Insert(0, Convert.ToString((int)temp % 10));
            intTen = (int)temp / 10;
        }
        if (intTen > 0)
            result.Insert(0, Convert.ToString(intTen));
        return result.ToString();
    }
}